import java.text.SimpleDateFormat;
import java.util.Date;

public class ThreadSleep {
    private static boolean flag = true;
    //private static Date startTime=new Date();

    public static void main(String[] args) {
        // 倒计时
        try {
            tenDown();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // 获取系统时间
        getTime();
        // 停止获取
        timeStop();
    }

    private static void tenDown() throws InterruptedException {
        int num=10;
        while(true){
            Thread.sleep(1000);
            System.out.println(num--);
            if(num<=0){
                break;
            }
        }
    }

    private static void getTime() {
        Date startTime=new Date(System.currentTimeMillis());
        while(flag){
            try{
                Thread.sleep(1000);
                System.out.println(new SimpleDateFormat("HH:mm:ss").format(startTime));
                // update time
                startTime=new Date(System.currentTimeMillis());
            }catch(InterruptedException e){
                e.printStackTrace();
                // 恢复中断状态
                Thread.currentThread().interrupt();
            }
        }
    }

    private static void timeStop() {
//        if("00:35:00".equals(startTime)){
//            flag=false;
//        }
        while(flag){
            try{
                Thread.sleep(1000);
                String curTime=new SimpleDateFormat("HH:mm:ss").format(new Date());
                if("00:43:00".equals(curTime)){
                    flag=false;
                    break;
                }
            }catch (InterruptedException e){
                e.printStackTrace();
                Thread.currentThread().interrupt();
            }
        }
    }
}
